//
//  PlayViewController.m
//  JiuKuGospel
//
//  Created by jiukuyinyue on 15-8-14.
//  Copyright (c) 2015年 JiuKuForApp. All rights reserved.
//

#import "PlayViewController.h"
#import "JKSongsMessStatus.h"
#import "ShengJingMessageViewController.h"
#import "JKMusicTempSaveFileModel.h"

#define LEFT 60
#define TOP 30
#define LAYER_YINYING 5.0
#define TABLEVIEW_LIEB_TOP 150
#define TODAY_CONTENT_HEIGHT 120
#define SHARE_MUSIC_URL @"http://m.9ku.com/play/"

@interface PlayViewController ()<UITableViewDelegate, UITableViewDataSource>
{
    BOOL isPlaying;
    NSUInteger lrcLineNumber;

}

@property (nonatomic, assign)BOOL loadNextAF;               //是否请求其他数据
@property (nonatomic, assign)BOOL sliderValueBool;          //控制滑块value与歌曲播放进度
@property (nonatomic, strong)NSTimer * timer;               //缓冲时间控制

@property (nonatomic, assign)BOOL suoPing;
@property (nonatomic, assign)BOOL isWifiOrNot;
@property (nonatomic, assign)BOOL loadAgain;                //继续请求
@property (nonatomic, assign)BOOL huanChongEndPlayBool; //缓冲value大于滑块value时自动播放;
@property (nonatomic, assign)BOOL suoPingNextBool;      //锁屏下一首控时

@property (nonatomic, strong)UILabel * zanwuLabel;      //暂无歌词提示
@property (nonatomic, strong)UILabel * headerNumLabel;  //列表数

//@property (nonatomic, assign)NSInteger playStyleNum; // 播放模式：（顺序、单曲、随机）

@property (nonatomic, strong)NSMutableArray * timeArray;
@property (nonatomic, strong)NSMutableDictionary * LRCDictionary;

@property (nonatomic, assign)BOOL allStopClick9Bool;
@property (nonatomic, assign)BOOL isNextSongBool;       //长时间未播放,10秒后强制播放下一首
@end

@implementation PlayViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    /*
    // 监听网络状态发生改变的通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkStateChange) name:kReachabilityChangedNotification object:nil];
    
    // 获得Reachability对象
    self.reachability = [Reachability reachabilityForInternetConnection];
    // 开始监控网络
    [self.reachability startNotifier];
     */
    
    self.view.backgroundColor = [UIColor whiteColor];
    //导航栏颜色
    self.navigationController.navigationBar.barTintColor = JK_HUISE_LINE_COLOR;
    //导航栏字体颜色
    self.navigationItem.title = @"播放";
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    
    UIButton * leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(0, 0, 30, 30);
//    NSString * backStr = [[NSBundle mainBundle] pathForResource:@"new返回@3x" ofType:@"png"];
    NSString * backStr = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"new返回%@", [TheHomeManager shareTheHomeManager].iPhone23] ofType:@"png"];

    [leftBtn setBackgroundImage:[UIImage imageWithContentsOfFile:backStr] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(leftBtnAction) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    
    
    UIButton * rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame = CGRectMake(0, 0, 40, 40);
//    [rightBtn setTitle:@"词" forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(rightBtnAction) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    
    
    lrcLineNumber = 0;
//    _timeArray = [[NSMutableArray alloc] initWithCapacity:10];
//    _LRCDictionary = [[NSMutableDictionary alloc] initWithCapacity:10];

    [TheHomeManager shareTheHomeManager].playVC = self;
    
    self.sliderValueBool = YES;
    self.suoPing = YES;


    //监听通知
    // ----(歌曲播放结束的监听通知)--
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(SongsEndNextPlay) name:AVPlayerItemDidPlayToEndTimeNotification object:nil];
    //歌曲播放阻断情况
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playStopClick) name:AVPlayerItemNewAccessLogEntryNotification object:nil];
    
    //耳机时机调用
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(siriNotification) name:AVAudioSessionRouteChangeNotification object:nil];
    //测试监听siri事件
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(allStopClick1) name:AVPlayerItemDidPlayToEndTimeNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(allStopClick2) name:AVPlayerItemFailedToPlayToEndTimeErrorKey object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(allStopClick3) name:AVPlayerItemLegibleOutputTextStylingResolutionDefault object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(allStopClick4) name:AVPlayerItemLegibleOutputTextStylingResolutionSourceAndRulesOnly object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(allStopClick5) name:AVPlayerItemNewAccessLogEntryNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(allStopClick6) name:AVPlayerItemNewErrorLogEntryNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(allStopClick7) name:AVPlayerItemPlaybackStalledNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(allStopClick8) name:AVPlayerItemTimeJumpedNotification object:nil];
    //本地时机调用
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(allStopClick9) name:AVAudioSessionInterruptionNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(allStopClick10) name:AVAudioSessionMediaServicesWereLostNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(allStopClick11) name:AVAudioSessionMediaServicesWereResetNotification object:nil];

    
//    [self setupUI];
    [self setupNewUI];
    
    if ([TheHomeManager shareTheHomeManager].shengjPlayBool == 0) {
//        [self playMusicWithIndex:_songIndex];
    }
//    [self playMusicWithIndex:_songIndex];
}

- (void)setupNewUI
{
    UIImageView * bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, self.view.height)];
    bgImageView.image = [UIImage imageNamed:@"player_bg@3x.png"];
    [self.view addSubview:bgImageView];
    
    //player_close@3x.png  50X28 16 9
    //返回控件
    UITapGestureRecognizer * backTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(backTap)];
    UIView * backView = [[UIView alloc] initWithFrame:CGRectMake(0, 20, 60, 44)];
    [backView addGestureRecognizer:backTap];
    [self.view addSubview:backView];
    UIImageView * backImageView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 17, 16, 9)];
    backImageView.image = [UIImage imageNamed:@"player_close@3x.png"];
    [backView addSubview:backImageView];
    
    //49 36
    //列表控件
    UITapGestureRecognizer * liebiaoTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showSongsList:)];
    UIView * liebiaoView = [[UIView alloc] initWithFrame:CGRectMake(self.view.width-60, backView.top, 60, 44)];
    [liebiaoView addGestureRecognizer:liebiaoTap];
    [self.view addSubview:liebiaoView];
    UIImageView * liebiaoImageView = [[UIImageView alloc] initWithFrame:CGRectMake(liebiaoView.width-15-16, 14, 16, 12)];
    liebiaoImageView.image = [UIImage imageNamed:@"player_list@3x.png"];
    [liebiaoView addSubview:liebiaoImageView];
    
    //分享
    UITapGestureRecognizer * shareTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(shareSong)];
    UIView * shareView = [[UIView alloc] initWithFrame:CGRectMake(liebiaoView.left, liebiaoView.bottom, 60, 44)];
    shareView.backgroundColor = [UIColor clearColor];
    [shareView addGestureRecognizer:shareTap];
    [self.view addSubview:shareView];

    
    //列表背景
    UITapGestureRecognizer * bgTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(removeBgView)];
    self.bgLieBiaoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, self.view.height)];
    _bgLieBiaoView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.7];
    _bgLieBiaoView.alpha = 0;
    [_bgLieBiaoView addGestureRecognizer:bgTap];
    [self.view addSubview:_bgLieBiaoView];
    
    //歌曲列表
    self.lieBiaoTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, TABLEVIEW_LIEB_TOP, self.view.width, self.view.height-TABLEVIEW_LIEB_TOP) style:UITableViewStylePlain];
    _lieBiaoTableView.delegate = self;
    _lieBiaoTableView.dataSource = self;
    [_bgLieBiaoView addSubview:_lieBiaoTableView];
    self.lieBiaoTableView.showsVerticalScrollIndicator = NO;

    //区头
//    UIView * headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, 50)];
    
    
    //区尾
//    UIView * footView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, 50)];
    

    
    
    
    
    //cell分割线顶头
    if ([self.lieBiaoTableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.lieBiaoTableView setSeparatorInset: UIEdgeInsetsZero];
    }
    if ([self.lieBiaoTableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [self.lieBiaoTableView setLayoutMargins: UIEdgeInsetsZero];
    }


    JKSongsMessStatus * status = [self.songListArr objectAtIndex:_songIndex];
    
    //歌名及专辑
    self.songNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(backView.right, liebiaoView.top+5, self.view.width-2*backView.width, 30)];
    _songNameLabel.font = FONT_19;
    _songNameLabel.textAlignment = NSTextAlignmentCenter;
    if (self.localPlayBool) {
        JKFileModel * fileModel = (JKFileModel *)status;
        _songNameLabel.text = fileModel.fileName;
    }else
    _songNameLabel.text = status.MusicName;
    _songNameLabel.textColor = [UIColor whiteColor];
    [self.view addSubview:_songNameLabel];
    
    self.songListNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(_songNameLabel.left, _songNameLabel.bottom, _songNameLabel.width, 20)];
    _songListNameLabel.font = FONT_14;
    _songListNameLabel.textAlignment = NSTextAlignmentCenter;
    if (self.localPlayBool) {
        JKFileModel * fileModel = (JKFileModel *)status;
        _songListNameLabel.text = fileModel.zjname;
    }else
        _songListNameLabel.text = status.album;
    _songListNameLabel.text = self.listNameStr;
    _songListNameLabel.textColor = [UIColor whiteColor];
    [self.view addSubview:_songListNameLabel];
    
    //专辑图片
    self.theImageView = [[UIImageView alloc] initWithFrame:CGRectMake((self.view.width-100)/2, _songListNameLabel.bottom +20, 100, 100)];
    _theImageView.layer.shadowColor = JK_BLACK2_COLOR.CGColor;
    _theImageView.layer.shadowOpacity = 0.4;
    _theImageView.layer.shadowOffset = CGSizeMake(0, 0);
    _theImageView.layer.shadowRadius = LAYER_YINYING;
    _theImageView.layer.masksToBounds = YES;
    _theImageView.layer.cornerRadius = _theImageView.width/2;
    [self.view addSubview:_theImageView];
    
    if ([self.imageUrl isEqualToString:@"http://img.9ku.com/fm/images/fm/noAlbumPic.png"]) {
//        _theImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@%@.png",self.listNameStr ,@"@3x"]];
    }else
        [_theImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", self.imageUrl]] placeholderImage:[UIImage imageNamed:@"450x450@3x.png"]];

    //歌词视图
    self.geciTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, _theImageView.bottom+15, self.view.width, self.view.height-_theImageView.bottom-15-105)];
    self.geciTableView.backgroundColor = [UIColor clearColor];
    self.geciTableView.delegate = self;
    self.geciTableView.dataSource = self;
    self.geciTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.geciTableView.tag = 550;
    [self.view addSubview:_geciTableView];
    
    
    //播放时长与总时长
    self.currentTimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, _geciTableView.bottom+10, 40, 30)];
    self.currentTimeLabel.text = @"00:00";
    self.currentTimeLabel.textColor = [UIColor whiteColor];
    self.currentTimeLabel.font = FONT_12;
    self.currentTimeLabel.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:_currentTimeLabel];
    
    self.durationTimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.view.width-45, _currentTimeLabel.top, _currentTimeLabel.width, _currentTimeLabel.height)];
    _durationTimeLabel.text = @"00:00";
    _durationTimeLabel.textColor = [UIColor whiteColor];
    _durationTimeLabel.font = FONT_12;
    _durationTimeLabel.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:_durationTimeLabel];
    
    //滑块与缓冲条
    self.sliderProgress = [[UISlider alloc] initWithFrame:CGRectMake(45, _geciTableView.bottom+10, self.view.width-2*45, 30)];
    [self.sliderProgress setThumbImage:[UIImage imageNamed:@"滑块按钮1@3x.png"] forState:UIControlStateNormal];
    [self.sliderProgress setThumbImage:[UIImage imageNamed:@"滑块按钮1@3x.png"] forState:UIControlStateHighlighted];
    [_sliderProgress addTarget:self action:@selector(backOrForwardAudio:) forControlEvents:UIControlEventValueChanged];
    [_sliderProgress addTarget:self action:@selector(sliderProgressTouchUp:) forControlEvents:UIControlEventTouchUpInside];
    [_sliderProgress addTarget:self action:@selector(sliderProgressTouchDown:) forControlEvents:UIControlEventTouchUpInside];
    _sliderProgress.maximumTrackTintColor = [UIColor clearColor];
    _sliderProgress.minimumTrackTintColor = JK_RED_COLOR;
    _sliderProgress.value = 0;
    
    self.HuanChongProgress = [[UIProgressView alloc] initWithFrame:CGRectMake(_sliderProgress.left+2, (_sliderProgress.height-2)/2+_sliderProgress.top, _sliderProgress.width-3, 2)];
    _HuanChongProgress.progress = 0;
    _HuanChongProgress.progressTintColor = [UIColor grayColor];
    [self.view addSubview:_HuanChongProgress];
    [self.view addSubview:_sliderProgress];

    //上一首,下一首,播放按钮
    self.beforeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _beforeBtn.frame = CGRectMake(80, _currentTimeLabel.bottom+10, 30, 30);
    [_beforeBtn addTarget:self action:@selector(beforeSongAction:) forControlEvents:UIControlEventTouchUpInside];
    NSString * beforeImageStr = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"new上一首p%@", [TheHomeManager shareTheHomeManager].iPhone23] ofType:@"png"];
    [_beforeBtn setBackgroundImage:[UIImage imageWithContentsOfFile:beforeImageStr] forState:UIControlStateNormal];
    [self.view addSubview:_beforeBtn];
//    _beforeBtn.backgroundColor = [UIColor cyanColor];
    
    if (self.view.height == 667) {
        
    }
    if (self.view.height == 736) {
    }
    
    self.nextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _nextBtn.frame = CGRectMake(self.view.width-_beforeBtn.left-_beforeBtn.width, _beforeBtn.top, _beforeBtn.width, _beforeBtn.height);
//    _nextBtn.backgroundColor = JK_CLEAR_COLOR;
    [_nextBtn addTarget:self action:@selector(nextSongAction:) forControlEvents:UIControlEventTouchUpInside];
    NSString * nextImageStr = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"new下一首p%@", [TheHomeManager shareTheHomeManager].iPhone23] ofType:@"png"];
    [_nextBtn setBackgroundImage:[UIImage imageWithContentsOfFile:nextImageStr] forState:UIControlStateNormal];
    [self.view addSubview:_nextBtn];
    
    self.playBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _playBtn.frame = CGRectMake((self.view.width-_beforeBtn.width-10)/2, _beforeBtn.top-5, _beforeBtn.width+10, _beforeBtn.height+10);
//    _playBtn.backgroundColor = JK_CLEAR_COLOR;
    [_playBtn addTarget:self action:@selector(playSongAction:) forControlEvents:UIControlEventTouchUpInside];
    NSString * playImageStr = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"new播放p%@", [TheHomeManager shareTheHomeManager].iPhone23] ofType:@"png"];
    [_playBtn setBackgroundImage:[UIImage imageWithContentsOfFile:playImageStr] forState:UIControlStateNormal];
    [self.view addSubview:_playBtn];

    //下载按钮,播放类型按钮
    UITapGestureRecognizer * downTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cellDownLoadActionIndex)];
    UIView * downLoadView = [[UIView alloc] initWithFrame:CGRectMake(20, _beforeBtn.top, _beforeBtn.width, _beforeBtn.height)];
    [downLoadView addGestureRecognizer:downTap];
    UIImageView * downLoadImageView = [[UIImageView alloc] initWithFrame:CGRectMake(7, 7, 16, 16)];
    downLoadImageView.image = [UIImage imageNamed:@"我的下载@3x.png"];
    [downLoadView addSubview:downLoadImageView];
    [self.view addSubview:downLoadView];
//    UIButton * downLoadBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//    downLoadBtn.frame = CGRectMake(20, _beforeBtn.top+7, 16, 16);
//    [downLoadBtn setBackgroundImage:[UIImage imageNamed:@"我的下载@3x.png"] forState:UIControlStateNormal];
//    [self.view addSubview:downLoadBtn];
    
    UITapGestureRecognizer * typeTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(changePlayType)];
    UIView * typeView = [[UIView alloc] initWithFrame:CGRectMake(self.view.width-downLoadView.right, downLoadView.top, downLoadView.width, downLoadView.height)];
    [typeView addGestureRecognizer:typeTap];
    self.typeImageView = [[UIImageView alloc] initWithFrame:CGRectMake(8, 10, 18, 14)];
    _typeImageView.userInteractionEnabled = YES;
    _typeImageView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"new循环%@", [TheHomeManager shareTheHomeManager].iPhone23] ofType:@"png"]];
    if (_playStyleNum == 1) {
        _typeImageView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"new随机%@", [TheHomeManager shareTheHomeManager].iPhone23] ofType:@"png"]];
    }
    [typeView addSubview:_typeImageView];
    [self.view addSubview:typeView];
//    typeImageView.backgroundColor = [UIColor cyanColor];
    
    //每日歌曲的内容
    self.contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, self.geciTableView.top, self.view.width-2*20, TODAY_CONTENT_HEIGHT)];
//    _contentLabel.text = self.contentStr;
    _contentLabel.numberOfLines = 0;
    _contentLabel.font = FONT_16;
    _contentLabel.textColor = [UIColor whiteColor];
    [self.view addSubview:_contentLabel];
    
    
//    self.playType = [UIButton buttonWithType:UIButtonTypeCustom];
//    _playType.frame = CGRectMake(self.view.width-downLoadBtn.right, downLoadBtn.top, 14, 10);
//    _playType.backgroundColor = JK_CLEAR_COLOR;
//    [_playType setBackgroundImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"new循环%@", [TheHomeManager shareTheHomeManager].iPhone23] ofType:@"png"]] forState:UIControlStateNormal];
//    [_playType addTarget:self action:@selector(changePlayType:) forControlEvents:UIControlEventTouchUpInside];
//    [self.view addSubview:_playType];

}

- (void)setupUI
{
    //暂无歌词提示
    self.zanwuLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 150, self.view.width, 30)];
    _zanwuLabel.textAlignment = NSTextAlignmentCenter;
    _zanwuLabel.font = FONT_20;
    _zanwuLabel.text = @"暂无歌词";
    _zanwuLabel.textColor = [UIColor grayColor];
    
    UIView * playViewPage = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, self.view.width-2*LEFT+TOP+90+30)];
    
    UIImageView * theImageView = [[UIImageView alloc] initWithFrame:CGRectMake(LEFT, TOP, self.view.width-2*LEFT, self.view.width-2*LEFT)];
//    theImageView.backgroundColor = JK_CLEAR_COLOR;
    theImageView.layer.shadowColor = JK_BLACK2_COLOR.CGColor;
    theImageView.layer.shadowOpacity = 0.4;
    theImageView.layer.shadowOffset = CGSizeMake(0, 0);
    theImageView.layer.shadowRadius = LAYER_YINYING;
//    [self.view addSubview:theImageView];
    [playViewPage addSubview:theImageView];
    
    if ([self.imageUrl isEqualToString:@"http://img.9ku.com/fm/images/fm/noAlbumPic.png"]) {
        theImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@%@.png",self.self.listNameStr ,@"@3x"]];
    }else
        [theImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", self.imageUrl]] placeholderImage:[UIImage imageNamed:@"450x450@3x.png"]];

    
    
    JKSongsMessStatus * status = [self.songListArr objectAtIndex:_songIndex];
    
    self.songNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, theImageView.bottom+30, self.view.width, 40)];
    _songNameLabel.font = FONT_22;
//    _songNameLabel.backgroundColor = JK_CLEAR_COLOR;
    _songNameLabel.textAlignment = NSTextAlignmentCenter;
    _songNameLabel.text = status.MusicName;
//    [self.view addSubview:_songNameLabel];
    [playViewPage addSubview:_songNameLabel];
    
    self.songListNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, _songNameLabel.bottom, _songNameLabel.width, 20)];
    _songListNameLabel.font = FONT_14;
//    _songListNameLabel.backgroundColor = JK_CLEAR_COLOR;
    _songListNameLabel.textAlignment = NSTextAlignmentCenter;
    _songListNameLabel.text = self.listNameStr;
//    [self.view addSubview:_songListNameLabel];
    [playViewPage addSubview:_songListNameLabel];
    
    // 播放器滚动视图
    REPagedScrollView *pageScrollView = [[REPagedScrollView alloc] initWithFrame:CGRectMake(0,64, self.view.width,self.view.width-2*LEFT+TOP+90+30)];
    pageScrollView.pageControl.pageIndicatorTintColor = JK_HUISE_COLOR;
    pageScrollView.pageControl.currentPageIndicatorTintColor = JK_RED_COLOR;
    [self.view addSubview:pageScrollView];

    [pageScrollView addPage:playViewPage];
    
    // 歌词视图
    self.geciTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 20, self.view.width, self.view.width-2*LEFT+TOP+90)];
    self.geciTableView.backgroundColor = [UIColor clearColor];
    self.geciTableView.delegate = self;
    self.geciTableView.dataSource = self;
    self.geciTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.geciTableView.tag = 550;
    [pageScrollView addPage:_geciTableView];
    [pageScrollView scrollToPageWithIndex:0 animated:YES];

    
    self.beforeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _beforeBtn.frame = CGRectMake(theImageView.left+10, pageScrollView.bottom, 30, 30);
//    _beforeBtn.backgroundColor = JK_CLEAR_COLOR;
    [_beforeBtn addTarget:self action:@selector(beforeSongAction:) forControlEvents:UIControlEventTouchUpInside];
//    NSString * beforeImageStr = [[NSBundle mainBundle] pathForResource:@"new上一首@3x" ofType:@"png"];
    NSString * beforeImageStr = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"new上一首p%@", [TheHomeManager shareTheHomeManager].iPhone23] ofType:@"png"];

    [_beforeBtn setBackgroundImage:[UIImage imageWithContentsOfFile:beforeImageStr] forState:UIControlStateNormal];
    [self.view addSubview:_beforeBtn];
    
    if (self.view.height == 667) {
        _beforeBtn.frame = CGRectMake(theImageView.left+10, pageScrollView.bottom+20, 30, 30);

    }
    if (self.view.height == 736) {
        _beforeBtn.frame = CGRectMake(theImageView.left+10, pageScrollView.bottom+25, 30, 30);
    }
    
    self.nextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _nextBtn.frame = CGRectMake(self.view.width-_beforeBtn.left-_beforeBtn.width, _beforeBtn.top, _beforeBtn.width, _beforeBtn.height);
//    _nextBtn.backgroundColor = JK_CLEAR_COLOR;
    [_nextBtn addTarget:self action:@selector(nextSongAction:) forControlEvents:UIControlEventTouchUpInside];
//    NSString * nextImageStr = [[NSBundle mainBundle] pathForResource:@"new下一首@3x" ofType:@"png"];
    NSString * nextImageStr = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"new下一首p%@", [TheHomeManager shareTheHomeManager].iPhone23] ofType:@"png"];

    [_nextBtn setBackgroundImage:[UIImage imageWithContentsOfFile:nextImageStr] forState:UIControlStateNormal];
    [self.view addSubview:_nextBtn];


    self.playBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _playBtn.frame = CGRectMake(theImageView.left+(theImageView.width-_beforeBtn.width)/2, _beforeBtn.top, _beforeBtn.width, _beforeBtn.height);
//    _playBtn.backgroundColor = JK_CLEAR_COLOR;
    [_playBtn addTarget:self action:@selector(playSongAction:) forControlEvents:UIControlEventTouchUpInside];
//    NSString * playImageStr = [[NSBundle mainBundle] pathForResource:@"new播放@3x" ofType:@"png"];
    NSString * playImageStr = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"new播放p%@", [TheHomeManager shareTheHomeManager].iPhone23] ofType:@"png"];

    [_playBtn setBackgroundImage:[UIImage imageWithContentsOfFile:playImageStr] forState:UIControlStateNormal];
    [self.view addSubview:_playBtn];

    
    self.sliderProgress = [[UISlider alloc] initWithFrame:CGRectMake(35, _beforeBtn.bottom+30, self.view.width-2*35, 30)];
    [self.sliderProgress setThumbImage:[UIImage imageNamed:@"滑块按钮1@3x.png"] forState:UIControlStateNormal];
    [self.sliderProgress setThumbImage:[UIImage imageNamed:@"滑块按钮1@3x.png"] forState:UIControlStateHighlighted];
    [_sliderProgress addTarget:self action:@selector(backOrForwardAudio:) forControlEvents:UIControlEventValueChanged];
    [_sliderProgress addTarget:self action:@selector(sliderProgressTouchUp:) forControlEvents:UIControlEventTouchUpInside];
    [_sliderProgress addTarget:self action:@selector(sliderProgressTouchDown:) forControlEvents:UIControlEventTouchUpInside];
    _sliderProgress.maximumTrackTintColor = [UIColor clearColor];
    _sliderProgress.minimumTrackTintColor = JK_RED_COLOR;
    _sliderProgress.value = 0;

    self.HuanChongProgress = [[UIProgressView alloc] initWithFrame:CGRectMake(_sliderProgress.left+2, (_sliderProgress.height-2)/2+_sliderProgress.top, _sliderProgress.width-3, 2)];
    _HuanChongProgress.progress = 0;
    _HuanChongProgress.progressTintColor = [UIColor grayColor];
    [self.view addSubview:_HuanChongProgress];
    [self.view addSubview:_sliderProgress];

    self.playType = [UIButton buttonWithType:UIButtonTypeCustom];
    _playType.frame = CGRectMake(20, self.view.height-50, 30, 30);
//    _playType.backgroundColor = JK_CLEAR_COLOR;
//    [_playType setBackgroundImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"new循环@3x" ofType:@"png"]] forState:UIControlStateNormal];
    [_playType setBackgroundImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"new循环%@", [TheHomeManager shareTheHomeManager].iPhone23] ofType:@"png"]] forState:UIControlStateNormal];

    [_playType addTarget:self action:@selector(changePlayType:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_playType];
    
    
    self.songsListBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _songsListBtn.frame = CGRectMake(self.view.width-_playType.right, _playType.top, _playType.width, _playType.height);
//    _songsListBtn.backgroundColor = JK_CLEAR_COLOR;
//    [_songsListBtn setBackgroundImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"歌曲列表@3x" ofType:@"png"]] forState:UIControlStateNormal];
    [_songsListBtn setBackgroundImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"歌曲列表%@", [TheHomeManager shareTheHomeManager].iPhone23] ofType:@"png"]] forState:UIControlStateNormal];

    [_songsListBtn addTarget:self action:@selector(showSongsList:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_songsListBtn];
    
    
    //列表背景
    UITapGestureRecognizer * bgTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(removeBgView)];
    self.bgLieBiaoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, self.view.height)];
    _bgLieBiaoView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.7];
    _bgLieBiaoView.alpha = 0;
    [_bgLieBiaoView addGestureRecognizer:bgTap];
    [self.view addSubview:_bgLieBiaoView];
    
    //歌曲列表
    self.lieBiaoTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, TABLEVIEW_LIEB_TOP, self.view.width, self.view.height-TABLEVIEW_LIEB_TOP) style:UITableViewStylePlain];
    _lieBiaoTableView.delegate = self;
    _lieBiaoTableView.dataSource = self;
    [_bgLieBiaoView addSubview:_lieBiaoTableView];

    //cell分割线顶头
    if ([self.lieBiaoTableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.lieBiaoTableView setSeparatorInset: UIEdgeInsetsZero];
    }
    if ([self.lieBiaoTableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [self.lieBiaoTableView setLayoutMargins: UIEdgeInsetsZero];
    }

}

- (void)leftBtnAction
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)backTap
{
    [self dismissViewControllerAnimated:YES completion:nil];
    
//    [self.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}

- (void)rightBtnAction
{
    
}

- (void)hideMB
{
    [MBProgressHUD hideHUDForView:self.view animated:YES];
}

- (void)changeLieBiaoNumLabel
{
//    UILabel * headerNumLabel = (UILabel *)[_lieBiaoTableView viewWithTag:519];
    UILabel * headerNumLabel = self.headerNumLabel;
    
    NSInteger count = 0;
    if ([TheHomeManager shareTheHomeManager].shengjPlayBool == 1 && !self.localPlayBool) {
        count = [TheHomeManager shareTheHomeManager].dataShengJingSongsArr.count;
    }else{
        count = self.songListArr.count;
    }
    if (_playStyleNum == 1) {
        headerNumLabel.text = [NSString stringWithFormat:@"随机播放(%ld首)", count];
    }
    if (_playStyleNum == -1) {
        headerNumLabel.text = [NSString stringWithFormat:@"单曲播放(%ld首)", count];
    }
    if (_playStyleNum == 0) {
        headerNumLabel.text = [NSString stringWithFormat:@"循环播放(%ld首)", count];
    }

}

#pragma mark - 网络监测
- (void)networkStateChange
{
    if ([SetHelper shareSetHelper].isOnOrOFF == YES) {
        if ([NetWorkTool isEnableWIFI]) {
//            self.isNetChange = NO;
//            self.isLocal = NO;
//            [self.showLocalView removeFromSuperview];
            //判断是否有网络连接
//            self.isHaveNet = 1;
        } else if ([NetWorkTool isEnable3G]) {
//            self.isNetChange = YES;
//            self.isLocal = YES;
//            // 判断是否有网络连接
//            self.isHaveNet = 2;
//            [self.view addSubview:self.showLocalView];
        } else {
            //飞行模式修改
//            self.isNetChange = YES;
//            self.isLocal = YES;
//            [self.showLocalView removeFromSuperview];
            //飞行模式修改
            //            [self noNetPlayCrash];
            ///判断是否有网络连接
//            self.isHaveNet = 3;
        }
    }else{
        MBProgressHUD *hud=[MBProgressHUD showHUDAddedTo:self.view animated:YES];
        hud.mode=MBProgressHUDModeText;//枚举类型不同的效果

        if ([NetWorkTool isEnableWIFI]) {
            hud.labelText=@"当前网络变为wifi状态";

        } else if ([NetWorkTool isEnable3G]) {
            hud.labelText=@"当前网络变为移动网络状态";

        } else {
            hud.labelText=@"网络已断开连接";
        }
        [self performSelector:@selector(removeMB) withObject:nil afterDelay:1.0];
    }

}

- (void)removeMB
{
    [MBProgressHUD hideHUDForView:self.view animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 分享歌曲
- (void)shareSong
{
    
}
//{
//    JKSongsMessStatus * status = [[JKSongsMessStatus alloc] init];
//    if ([TheHomeManager shareTheHomeManager].shengjPlayBool == 1) {
//        if (!self.localPlayBool) {
//            status.songID = [[[TheHomeManager shareTheHomeManager].dataShengJingSongsArr objectAtIndex:self.songIndex] objectForKey:@"musicId"];
//            status.singerName = [[[TheHomeManager shareTheHomeManager].dataShengJingSongsArr objectAtIndex:self.songIndex] objectForKey:@"name"];
//            status.MusicName = [[[TheHomeManager shareTheHomeManager].dataShengJingSongsArr objectAtIndex:self.songIndex] objectForKey:@"title"];
//        }else{
//            JKFileModel * fileModel = [self.songListArr objectAtIndex:_songIndex];
//            status.songID = fileModel.songID;
//            status.singerName = fileModel.singerName;
//            status.MusicName = fileModel.fileName;
//        }
//    }else{
//         status = [_songListArr objectAtIndex:_songIndex];
//
//    }
//    
//
//
//    
//    //1、构造分享内容
//    //1.1、要分享的图片（以下分别是网络图片和本地图片的生成方式的示例）
//    id<ISSCAttachment> remoteAttachment = [ShareSDKCoreService attachmentWithUrl:@"http://f.hiphotos.bdimg.com/album/w%3D2048/sign=df8f1fe50dd79123e0e09374990c5882/cf1b9d16fdfaaf51e6d1ce528d5494eef01f7a28.jpg"];
//    //        id<ISSCAttachment> localAttachment = [ShareSDKCoreService attachmentWithPath:[[NSBundle mainBundle] pathForResource:@"shareImg" ofType:@"png"]];
//    
//    //1.2、以下参数分别对应：内容、默认内容、图片、标题、链接、描述、分享类型
//    id<ISSContent> publishContent = [ShareSDK content:status.MusicName
//                                       defaultContent:nil
//                                                image:remoteAttachment
//                                                title:status.singerName
//                                                  url:[NSString stringWithFormat:@"%@%@.htm", SHARE_MUSIC_URL, status.songID]
//                                          description:nil
//                                            mediaType:SSPublishContentMediaTypeMusic];
//    
//    //1+、创建弹出菜单容器（iPad应用必要，iPhone应用非必要）
//    id<ISSContainer> container = [ShareSDK container];
//    [container setIPadContainerWithView:self.view arrowDirect:UIPopoverArrowDirectionUp];
//    
//    //2、展现分享菜单
//    [ShareSDK showShareActionSheet:container
//                         shareList:nil
//                           content:publishContent
//                     statusBarTips:NO
//                       authOptions:nil
//                      shareOptions:nil
//                            result:^(ShareType type, SSResponseState state, id<ISSPlatformShareInfo> statusInfo, id<ICMErrorInfo> error, BOOL end) {
//                                
//                                NSLog(@"=== response state :%zi ",state);
//                                
//                                //可以根据回调提示用户。
//                                if (state == SSResponseStateSuccess)
//                                {
//                                    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"分享成功"
//                                                                                    message:nil
//                                                                                   delegate:self
//                                                                          cancelButtonTitle:@"确定"
//                                                                          otherButtonTitles:nil, nil];
//                                    [alert show];
//                                }
//                                else if (state == SSResponseStateFail)
//                                {
//                                    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"分享失败"
//                                                                                    message:nil
//                                                                                   delegate:self
//                                                                          cancelButtonTitle:@"确定"
//                                                                          otherButtonTitles:nil, nil];
//                                    [alert show];
//                                }
//                            }];
//    
//
//}

#pragma mark - 上一首下一首播放
- (void)beforeSongAction:(UIButton *)btn
{
    if (!_suoPingNextBool) {
        NSLog(@"锁屏相关方法Next");
        _suoPingNextBool = YES;
        [self performSelector:@selector(changeSuoPingNextBool) withObject:nil afterDelay:1.5];
    }else{
        return;
    }

    if (_playStyleNum == 0) {
        _songIndex--;
        if (_songIndex == -1) {
            //圣经到最后 切换圣经  不循环
            if ([TheHomeManager shareTheHomeManager].shengjPlayBool == 1 && !self.localPlayBool) {
                    NSIndexPath * tempIndex = nil;
                    if ([TheHomeManager shareTheHomeManager].tempIndexPath.section == 0) {
                        if ([TheHomeManager shareTheHomeManager].tempIndexPath.row == 0) {
                            tempIndex = [NSIndexPath indexPathForRow:[TheHomeManager shareTheHomeManager].dataXinyeuArr.count-1 inSection:1];
                            [[TheHomeManager shareTheHomeManager] localShengJingSongMessage:[[[TheHomeManager shareTheHomeManager].dataXinyeuArr objectAtIndex:tempIndex.row] objectForKey:@"id"]];
                        }else{
                            tempIndex = [NSIndexPath indexPathForRow:[TheHomeManager shareTheHomeManager].tempIndexPath.row-1 inSection:[TheHomeManager shareTheHomeManager].tempIndexPath.section];
                            [[TheHomeManager shareTheHomeManager] localShengJingSongMessage:[[[TheHomeManager shareTheHomeManager].dataJiuyueArr objectAtIndex:tempIndex.row] objectForKey:@"id"]];
                        }

                    }else{
                        if ([TheHomeManager shareTheHomeManager].tempIndexPath.row == 0) {
                            tempIndex = [NSIndexPath indexPathForRow:[TheHomeManager shareTheHomeManager].dataJiuyueArr.count-1 inSection:0];
                            [[TheHomeManager shareTheHomeManager] localShengJingSongMessage:[[[TheHomeManager shareTheHomeManager].dataJiuyueArr objectAtIndex:tempIndex.row] objectForKey:@"id"]];
                        }else{
                            tempIndex = [NSIndexPath indexPathForRow:[TheHomeManager shareTheHomeManager].tempIndexPath.row-1 inSection:[TheHomeManager shareTheHomeManager].tempIndexPath.section];
                            [[TheHomeManager shareTheHomeManager] localShengJingSongMessage:[[[TheHomeManager shareTheHomeManager].dataXinyeuArr objectAtIndex:tempIndex.row] objectForKey:@"id"]];
                        }
                    }
                    [TheHomeManager shareTheHomeManager].tempIndexPath = tempIndex;
                
                    _songIndex = [TheHomeManager shareTheHomeManager].dataShengJingSongsArr.count-1;
                    [TheHomeManager shareTheHomeManager].tempCount = [TheHomeManager shareTheHomeManager].dataShengJingSongsArr.count-1;
                NSLog(@"%ld", _songIndex);
                NSLog(@"%ld", [TheHomeManager shareTheHomeManager].tempCount);
                
                
                    NSString * uid = [[[TheHomeManager shareTheHomeManager].dataShengJingSongsArr objectAtIndex:[TheHomeManager shareTheHomeManager].tempCount] objectForKey:@"id"];
                    [[TheHomeManager shareTheHomeManager] localShengJingLrc:uid];
                    return;
                    
            }
            _songIndex = _songListArr.count-1;
        }
    }
    if (_playStyleNum == 1) {
        _songIndex = arc4random()%_songListArr.count;
        NSLog(@"%ld", _songIndex);
    }
    if (_playStyleNum == -1) {
    }
    
    if ([TheHomeManager shareTheHomeManager].shengjPlayBool == 1 && !self.localPlayBool) {
        //刷新圣经数据
        if (self.songIndex == -1) {
            self.songIndex = [TheHomeManager shareTheHomeManager].dataShengJingSongsArr.count - 1;
        }
        [TheHomeManager shareTheHomeManager].tempCount = self.songIndex;
        [[TheHomeManager shareTheHomeManager].playVCShengj changeShengJingMessage];
        return;
    }

    [self playMusicWithIndex:_songIndex];

    NSLog(@"上一首");
}

- (void)nextSongAction:(UIButton *)btn
{
    if (!_suoPingNextBool) {
        NSLog(@"锁屏相关方法Next");
        _suoPingNextBool = YES;
        [self performSelector:@selector(changeSuoPingNextBool) withObject:nil afterDelay:1.5];
    }else{
        return;
    }

    if (_playStyleNum == 0) {
        _songIndex++;
        //圣经到最后 切换圣经  不循环
        if ([TheHomeManager shareTheHomeManager].shengjPlayBool == 1 && !self.localPlayBool) {
            if (_songIndex == [TheHomeManager shareTheHomeManager].dataShengJingSongsArr.count) {
                _songIndex = 0;
                NSIndexPath * tempIndex = nil;
                if ([TheHomeManager shareTheHomeManager].tempIndexPath.section == 0) {
                    if ([TheHomeManager shareTheHomeManager].tempIndexPath.row == [TheHomeManager shareTheHomeManager].dataJiuyueArr.count-1) {
                        tempIndex = [NSIndexPath indexPathForRow:0 inSection:1];
                        [[TheHomeManager shareTheHomeManager] localShengJingSongMessage:[[[TheHomeManager shareTheHomeManager].dataXinyeuArr objectAtIndex:tempIndex.row] objectForKey:@"id"]];
                    }else{
                        tempIndex = [NSIndexPath indexPathForRow:[TheHomeManager shareTheHomeManager].tempIndexPath.row+1 inSection:[TheHomeManager shareTheHomeManager].tempIndexPath.section];
                        [[TheHomeManager shareTheHomeManager] localShengJingSongMessage:[[[TheHomeManager shareTheHomeManager].dataJiuyueArr objectAtIndex:tempIndex.row] objectForKey:@"id"]];
                    }

                }else{
                    if ([TheHomeManager shareTheHomeManager].tempIndexPath.row == [TheHomeManager shareTheHomeManager].dataXinyeuArr.count-1) {
                        tempIndex = [NSIndexPath indexPathForRow:0 inSection:0];
                        [[TheHomeManager shareTheHomeManager] localShengJingSongMessage:[[[TheHomeManager shareTheHomeManager].dataJiuyueArr objectAtIndex:tempIndex.row] objectForKey:@"id"]];
                    }else{
                        tempIndex = [NSIndexPath indexPathForRow:[TheHomeManager shareTheHomeManager].tempIndexPath.row+1 inSection:[TheHomeManager shareTheHomeManager].tempIndexPath.section];
                        [[TheHomeManager shareTheHomeManager] localShengJingSongMessage:[[[TheHomeManager shareTheHomeManager].dataXinyeuArr objectAtIndex:tempIndex.row] objectForKey:@"id"]];
                    }
                }
                [TheHomeManager shareTheHomeManager].tempIndexPath = tempIndex;
                [TheHomeManager shareTheHomeManager].tempCount = 0;
                
                NSString * uid = [[[TheHomeManager shareTheHomeManager].dataShengJingSongsArr objectAtIndex:[TheHomeManager shareTheHomeManager].tempCount] objectForKey:@"id"];
                [[TheHomeManager shareTheHomeManager] localShengJingLrc:uid];
                return;

            }
        }
        if (_songIndex == _songListArr.count) {
            _songIndex = 0;
        }
    }
    if (_playStyleNum == 1) {
        if ([TheHomeManager shareTheHomeManager].shengjPlayBool == 1 && !self.localPlayBool) {
            _songIndex = arc4random()%[TheHomeManager shareTheHomeManager].dataShengJingSongsArr.count;
        }else
        _songIndex = arc4random()%_songListArr.count;
        NSLog(@"%ld", _songIndex);
    }
    if (_playStyleNum == -1) {
    }
    
    if ([TheHomeManager shareTheHomeManager].shengjPlayBool == 1 && !self.localPlayBool) {
        //刷新圣经数据
        if ([TheHomeManager shareTheHomeManager].dataShengJingSongsArr.count == self.songIndex) {
            self.songIndex = 0;
        }
        [TheHomeManager shareTheHomeManager].tempCount = self.songIndex;
        [[TheHomeManager shareTheHomeManager].playVCShengj changeShengJingMessage];
        return;
    }
    [self playMusicWithIndex:_songIndex];
    NSLog(@"下一首");
}

- (void)playSongAction:(UIButton *)btn
{
    if (isPlaying) {
        [self pauseAudio];
        [self.playBtn setBackgroundImage:[UIImage imageNamed:@"new暂停p@3x"] forState:UIControlStateNormal];
        isPlaying = NO;
    } else {
        [self resumeAudio];
        [self.playBtn setBackgroundImage:[UIImage imageNamed:@"new播放p@3x"] forState:UIControlStateNormal];
        isPlaying = YES;
    }
    [TheHomeManager shareTheHomeManager].isPlaying = isPlaying;
    [[NSNotificationCenter defaultCenter] postNotificationName:@"ChangeSongPlayBtn" object:nil];

    NSLog(@"暂停与播放");
}

- (void)changePlayType
{
    _playStyleNum += 1;
    NSString* name = nil;
    NSString* title = nil;
    NSString* tishi = nil;
    switch (_playStyleNum) {
        case 0:
            name = @"playerXunhuanAll.png";
            title = @"new循环";
            tishi = @"列表循环";
            break;
        case 1:
            name = @"playerXunhuanRandom.png";
            title = @"new随机";
            tishi = @"列表随机";
            break;
        case 2:
            name = @"playerXunhuanOne.png";
            title = @"new单曲";
            tishi = @"单曲循环";
            _playStyleNum=-1;
            break;
        default:
            break;
    }
//    [_playType setBackgroundImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@%@", title, [TheHomeManager shareTheHomeManager].iPhone23] ofType:@"png"]] forState:UIControlStateNormal];
    _typeImageView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@%@", title, [TheHomeManager shareTheHomeManager].iPhone23] ofType:@"png"]];

    _typeLieBImageView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@1%@", title, [TheHomeManager shareTheHomeManager].iPhone23] ofType:@"png"]];

    [self changeLieBiaoNumLabel];

    MBProgressHUD *hud=[MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.mode=MBProgressHUDModeText;//枚举类型不同的效果
    
    hud.labelText=[NSString stringWithFormat:@"切换为%@", tishi];
    [self performSelector:@selector(hideMB) withObject:nil afterDelay:1.0];

    NSLog(@"改变播放类型");
}

//- (void)showSongsList:(UIButton *)btn
//{
//    [_lieBiaoTableView reloadData];
//    [UIView beginAnimations:nil context:nil];
//    [UIView setAnimationDuration:0.4];
//    _bgLieBiaoView.alpha = 1;
//    [UIView commitAnimations];
//    
//    NSLog(@"展现歌曲播放列表");
//}

- (void)showSongsList:(UITapGestureRecognizer *)tap
{
    [self.view bringSubviewToFront:_bgLieBiaoView];
    
    [_lieBiaoTableView reloadData];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.4];
    _bgLieBiaoView.alpha = 1;
    [UIView commitAnimations];
    
    NSLog(@"展现歌曲播放列表");
}

// 暂停
-(void)pauseAudio {
    [[AFSoundManager sharedManager] pause];
    NSLog(@"暂停啦暂停啦暂停啦暂停啦");
}

// 继续播放
-(void)resumeAudio {
    _suoPing = YES;
    [[AFSoundManager sharedManager] resume];
    NSLog(@"播放啦播放啦播放啦播放啦");
}

#pragma mark - 滑块出发方法
-(void)backOrForwardAudio:(UISlider *)sender {
    NSLog(@"valueChange");
    self.sliderValueBool = NO;
    
}

- (void)sliderProgressTouchUp:(UISlider *)sender
{
    
    self.suoPing = YES;
    
    if (sender.value == 1) {
        [self nextSongAction:nil];
        return;
    }
    
    if (self.sliderProgress.value > self.HuanChongProgress.progress && self.sliderProgress.value < 0.98) {
        NSLog(@"进度条大于缓冲");
        [self.playBtn setBackgroundImage:[UIImage imageNamed:@"playerPlayPlay"] forState:UIControlStateNormal];
        isPlaying = NO;
        self.huanChongEndPlayBool = YES;
    }else{
        self.huanChongEndPlayBool = NO;
    }
    
    NSLog(@"senderValue ==== %f", sender.value);
    if (self.huanChongEndPlayBool) {
        isPlaying = YES;
        [self playSongAction:nil];
        [self performSelector:@selector(AVPlayerTimerSliderIsEqualHuanChong) withObject:nil afterDelay:0.2];
    }else
        [[AFSoundManager sharedManager]moveToSection:sender.value];
    
    
    
    self.sliderValueBool = YES;

}
- (void)sliderProgressTouchDown:(UISlider *)sender
{
    NSLog(@"down");
}

#pragma mark - 实现播放
- (void)playMusicWithIndex:(NSInteger)count
{
    if ([TheHomeManager shareTheHomeManager].shengjPlayBool == 1 && !self.localPlayBool) {
        
    }else{
        [TheHomeManager shareTheHomeManager].isPlayShengJ = NO;
    }
        
    
    if (self.shige400Bool) {
        JKSongsMessStatus * status = [_songListArr objectAtIndex:count];
//        NSNumber * num = (NSNumber *)status.n;
//        NSString * str = [num stringValue];
        [self.shige400Lrc reloadShigeLrc:count LrcNum:status.n];
    }
    
    
    
    
    if ([TheHomeManager shareTheHomeManager].shengjPlayBool == 1) {
        if (!self.localPlayBool) {
            //更换播放页数据
            NSString * wma = [[[TheHomeManager shareTheHomeManager].dataShengJingSongsArr objectAtIndex:self.songIndex] objectForKey:@"wma"];
            NSLog(@"%@", wma);
            
            JKSongsMessStatus * status = [[JKSongsMessStatus alloc] init];
            status.wma = wma;
            status.wma_time = [[[TheHomeManager shareTheHomeManager].dataShengJingSongsArr objectAtIndex:self.songIndex] objectForKey:@"time"];
            status.MusicName = [[[TheHomeManager shareTheHomeManager].dataShengJingSongsArr objectAtIndex:self.songIndex] objectForKey:@"title"];
            status.singerName = [[[TheHomeManager shareTheHomeManager].dataShengJingSongsArr objectAtIndex:self.songIndex] objectForKey:@"name"];
            status.album = [[[TheHomeManager shareTheHomeManager].dataShengJingSongsArr objectAtIndex:self.songIndex] objectForKey:@"name"];
            
            _songNameLabel.text = status.MusicName;
            _songListNameLabel.text = status.album;
            _durationTimeLabel.text = @"";
            NSInteger mp3Time = [status.wma_time integerValue];
            NSLog(@"%@", [[[TheHomeManager shareTheHomeManager].dataShengJingSongsArr objectAtIndex:self.songIndex] objectForKey:@"time"]);
            NSLog(@"%@", status.wma_time);
            NSLog(@"%d", mp3Time);
            
            NSInteger fen = mp3Time/60000;
            NSInteger miao = mp3Time%60000/1000;
            if (fen<10) {
                if (miao<10) {
                    _durationTimeLabel.text = [NSString stringWithFormat:@"0%ld:0%ld", fen,miao];
                }else
                    _durationTimeLabel.text = [NSString stringWithFormat:@"0%ld:%ld", fen,miao];
            }else{
                if (miao<10) {
                    _durationTimeLabel.text = [NSString stringWithFormat:@"%ld:0%ld", fen,miao];
                }else
                    _durationTimeLabel.text = [NSString stringWithFormat:@"%ld:%ld", fen,miao];
            }
            
            
            [self playMusicWithSongLink:status];
            return;
        }
        
#warning ---12.15本地歌曲为0问题---
        if (self.songListArr.count == 0) {
            return;
        }
        //播放本地
        NSLog(@"%ld %ld",_songIndex , self.songListArr.count);
        JKFileModel * fileModel = [self.songListArr objectAtIndex:_songIndex];
        NSLog(@"%@", fileModel.pic);
        NSLog(@"%@", fileModel.pic1);
        NSLog(@"%@", fileModel.pic300);

        _songNameLabel.text = fileModel.fileName;
        _songListNameLabel.text = fileModel.zjname;
        [_theImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", fileModel.pic]] placeholderImage:[UIImage imageNamed:@"450x450@3x.png"]];

        _durationTimeLabel.text = @"";
        NSInteger mp3Time = [fileModel.mp3time integerValue];
        NSInteger fen = mp3Time/60000;
        NSInteger miao = mp3Time%60000/1000;
        if (fen<10) {
            if (miao<10) {
                _durationTimeLabel.text = [NSString stringWithFormat:@"0%ld:0%ld", fen,miao];
            }else
                _durationTimeLabel.text = [NSString stringWithFormat:@"0%ld:%ld", fen,miao];
        }else{
            if (miao<10) {
                _durationTimeLabel.text = [NSString stringWithFormat:@"%ld:0%ld", fen,miao];
            }else
                _durationTimeLabel.text = [NSString stringWithFormat:@"%ld:%ld", fen,miao];
        }
        
        JKMusicTempSaveFileModel * tempModel = [[JKMusicTempSaveFileModel alloc] init];
        tempModel.fileName = fileModel.fileName;
        tempModel.singerName = fileModel.singerName;
        tempModel.zjname = fileModel.zjname;
        tempModel.fileURL = fileModel.fileURL;
        tempModel.pic300 = fileModel.pic;
        tempModel.mp3time = fileModel.mp3time;
        [self playLocationMp4Music:tempModel];
        
        return;
    }
    if ([TheHomeManager shareTheHomeManager].shengjPlayBool == 0) {
        
    }
    
    
    _suoPing = YES;
    JKSongsMessStatus * status = [_songListArr objectAtIndex:count];
    _songNameLabel.text = status.MusicName;
    _songListNameLabel.text = status.album;
    if (self.imageUrl.length != 0) {
        [_theImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", self.imageUrl]] placeholderImage:[UIImage imageNamed:@"450x450@3x.png"]];
    }else
    [_theImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", status.image]] placeholderImage:[UIImage imageNamed:@"450x450@3x.png"]];
    _durationTimeLabel.text = @"";
    NSInteger mp3Time = [status.wma_time integerValue];
    NSInteger fen = mp3Time/60000;
    NSInteger miao = mp3Time%60000/1000;
    if (fen<10) {
        if (miao<10) {
            _durationTimeLabel.text = [NSString stringWithFormat:@"0%ld:0%ld", fen,miao];
        }else
            _durationTimeLabel.text = [NSString stringWithFormat:@"0%ld:%ld", fen,miao];
    }else{
        if (miao<10) {
            _durationTimeLabel.text = [NSString stringWithFormat:@"%ld:0%ld", fen,miao];
        }else
            _durationTimeLabel.text = [NSString stringWithFormat:@"%ld:%ld", fen,miao];
    }

    //每日灵修content
    if (status.content.length > 0) {
        NSLog(@"%@", status.content);
        self.contentLabel.text = status.content;
    }
    
    [self playMusicWithSongLink:status];
}

- (void)playMusicWithSongLink:(JKSongsMessStatus *)status
{
    NSLog(@"%@", status.wma);
    
    [TheHomeManager shareTheHomeManager].isPlaying = YES;
//    [TheHomeManager shareTheHomeManager].shengjPlayBool = 0;
    [TheHomeManager shareTheHomeManager].status = status;
    if (self.imageUrl.length != 0) {
        [TheHomeManager shareTheHomeManager].imageShengJUrl = self.imageUrl;
    }else
        [TheHomeManager shareTheHomeManager].imageShengJUrl = status.image;
    [TheHomeManager shareTheHomeManager].zjNameStr = _listNameStr;
    [TheHomeManager shareTheHomeManager].songIndex = _songIndex;
    [[NSNotificationCenter defaultCenter] postNotificationName:@"ChangeSongMess" object:nil];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"ChangeSongPlayBtn" object:nil];


//    [self initLRC];
//    [self.timer invalidate];
    [[AFSoundManager sharedManager].timer invalidate];
    _HuanChongProgress.progress = 0;
    _suoPing = YES;
    _sliderProgress.value = 0;
    isPlaying = YES;
    lrcLineNumber = 0;
    self.loadNextAF = YES;

    
    if ([TheHomeManager shareTheHomeManager].musicTempSaveBool) {
        [self stopTempSaveDownLoad];
        [self cleanAllData];
        [TheHomeManager shareTheHomeManager].musicTempSaveBool = NO;
    }

    //播放缓存本地歌曲
    NSLog(@"缓存中存在该歌曲");
    NSString * document1 = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES)firstObject];
    NSString *plistPath1 = [document1 stringByAppendingPathComponent:@"TempSaveMusicFile"];
    
    NSMutableArray *downMp4PlistArray = [NSMutableArray arrayWithContentsOfFile:plistPath1];
    
    for (int a = 0; a < downMp4PlistArray.count; a++) {
        NSDictionary * dic = [downMp4PlistArray objectAtIndex:a];
        NSString * string = [dic objectForKey:@"fileURL"];
        
        JKMusicTempSaveFileModel * model = [[JKMusicTempSaveFileModel alloc] init];
        model.singerName = [dic objectForKey:@"singerName"];
        model.pic1 = [dic objectForKey:@"pic"];
        model.fileURL = [dic objectForKey:@"fileURL"];
        model.fileName = [dic objectForKey:@"filename"];
        model.fileSize = [dic objectForKey:@"filesize"];
        model.zjname = [dic objectForKey:@"zhuanjiName"];
        model.mp3time = [dic objectForKey:@"songTime"];
        model.songID = [dic objectForKey:@"songID"];
        
        
        if ([string isEqualToString:status.wma]) {
            [self playLocationMp4Music:model];
            return;
        }
    }

    NSLog(@"%@", status.wma);
    [[AFSoundManager sharedManager] startStreamingRemoteAudioFromURL:status.wma andBlock:^(int percentage, CGFloat elapsedTime, CGFloat timeRemaining, NSError *error, BOOL finished) {
        
        if (!error) {
            
            NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
            [formatter setDateFormat:@"mm:ss"];
            
            NSDate *elapsedTimeDate = [NSDate dateWithTimeIntervalSince1970:elapsedTime];
            NSString * tempTimeStr = [formatter stringFromDate:elapsedTimeDate];

            
            if ([self.timeArray containsObject:tempTimeStr]) {
                NSInteger lrcPlace = [_timeArray indexOfObject:tempTimeStr];
                lrcLineNumber = lrcPlace;
                [self.geciTableView reloadData];
                NSIndexPath *indexPath = [NSIndexPath indexPathForRow:lrcPlace inSection:0];
                [self.geciTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionMiddle];
                if ([TheHomeManager shareTheHomeManager].shengjPlayBool == 1) {
                    [[TheHomeManager shareTheHomeManager].playVCShengj reloadShengJingTabCell:lrcLineNumber];
                }

            }

            self.currentTimeLabel.text = [formatter stringFromDate:elapsedTimeDate];
            
            /*
            // 网络监测
            Reachability * reach = [Reachability reachabilityWithHostName:@"www.apple.com"];
            if ([SetHelper shareSetHelper].isOnOrOFF == YES) {
                if ([reach isReachableViaWiFi]) {
                    
                }else if ([reach isReachableViaWWAN]) {
                    UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"当前模式为仅WiFi状态下可以播放，请在设置页面设置！" delegate:self cancelButtonTitle:nil otherButtonTitles:@"知道了", nil];
                    [alert show];
                    [self playSongAct:nil];
                    return;
                }else {
                    
                }
            }else{
                
            }
            */
            
            
            
            
            
            //判断是否请求歌词数据
            if (self.loadNextAF) {
                //添加一个判断,看该歌曲是否之前下载过,没有的话进行下载,有的话接着下载
                [self tempSaveDownLoadMusic];
                [self.timer invalidate];
                self.timer = [NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(huanChongClick) userInfo:nil repeats:YES];
                self.loadNextAF = NO;
                
                if (self.contentStr.length != 0) {
                    [self.timeArray removeAllObjects];
                    [self.LRCDictionary removeAllObjects];
                    
                    [self.timeArray addObjectsFromArray:[TheHomeManager shareTheHomeManager].timeArr];
                    [self.LRCDictionary setValuesForKeysWithDictionary:[TheHomeManager shareTheHomeManager].dataShengJingLrcDic];
                    NSLog(@"self.LRCDictionary = %@", self.LRCDictionary);
                    [self.geciTableView reloadData];

                }else{
                    if ([TheHomeManager shareTheHomeManager].shengjPlayBool == 1) {
                        [self initLRC:@""];
                    }else{
                        [self performSelector:@selector(doClickBeLatePlaySuccess) withObject:nil afterDelay:0.5];
                    }
                }
            }
            
            
            if (self.suoPing && timeRemaining>0) {
                NSLog(@"%@", self.imageUrl);
                NSLog(@"%@", status.image);
                NSLog(@"%@", status.image300);
                if (self.imageUrl.length != 0) {
                    [self setLockScreenNowPlayingInfoSongName:status.MusicName singer:self.listNameStr zjName:@"" zjImage:self.imageUrl duration:timeRemaining];
                }else{
                    [self setLockScreenNowPlayingInfoSongName:status.MusicName singer:self.listNameStr zjName:@"" zjImage:status.image duration:timeRemaining];
                }
                self.suoPing = NO;
            }
            
            
            /*
            if (self.suoPing && timeRemaining>0) {
                [self setLockScreenNowPlayingInfoSongName:status.musicname singer:status.singer zjName:status.zhuanjiName zjImage:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",kImageURL, status.pic1]] duration:timeRemaining];
                self.suoPing = NO;
            }
            */
            
            
            
            
            
            //            if ([_timeArray containsObject:tempTimeStr]) {
            //                NSInteger lrcPlace = [_timeArray indexOfObject:tempTimeStr];
            //                lrcLineNumber = lrcPlace;
            //                [self.geciTableView reloadData];
            //                NSIndexPath *indexPath = [NSIndexPath indexPathForRow:lrcPlace inSection:0];
            //                [self.geciTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionMiddle];
            //                /*
            //                 [UIView beginAnimations:nil context:nil];
            //                 [UIView setAnimationDelay:2];
            //                 self.geciTableView.contentOffset = CGPointMake(0, 44*lrcPlace);
            //                 [UIView commitAnimations];*/
            //            }
            
            
            
            //            NSArray * tempTimeArr = [tempTimeStr componentsSeparatedByString:@":"];
            //            NSInteger timeNumber = [[tempTimeArr objectAtIndex:0] integerValue]*60 + [[tempTimeArr objectAtIndex:1] integerValue];
            //            if (self.timeNumber >= timeNumber) {
            //                self.currentTimeLabel.text = [formatter stringFromDate:elapsedTimeDate];
            //            }
            //            self.durationTimeLabel.text = self.tempTime;
            //            if ([self.currentTimeLabel.text isEqualToString:self.tempTime] || [self.currentTimeLabel.text isEqualToString:bugTime]) {
            //                self.count099++;
            //                if (self.count099 == 10) {
            //                    [self SongsEndNextPlay];
            //                }
            //            }
            
            
            //            if (self.sliderValueBool) {
            //                self.sliderProgress.value = percentage * 0.01;
            //            }
            
            if (self.sliderValueBool) {
                self.sliderProgress.value = percentage * 0.01;
                [TheHomeManager shareTheHomeManager].sliderValue = _sliderProgress.value;
                [[NSNotificationCenter defaultCenter] postNotificationName:@"ChangeSongPlayValue" object:nil];
            }
            
        } else {
            
            //            DLog(@"playError------%@", [error description]);
        }
    }];

}
//
- (void)playLocationMp4Music:(JKMusicTempSaveFileModel *)file
{
    NSLog(@"%@", file.fileURL);
    
    
}





- (void)initLRC:(NSString *)strGC
{
    if ([TheHomeManager shareTheHomeManager].shengjPlayBool == 1) {
        [self.timeArray removeAllObjects];
        [self.LRCDictionary removeAllObjects];
        
        [self.timeArray addObjectsFromArray:[TheHomeManager shareTheHomeManager].timeArr];
        [self.LRCDictionary setValuesForKeysWithDictionary:[TheHomeManager shareTheHomeManager].dataShengJingLrcDic];
        [self.geciTableView reloadData];
        
        return;
    }
    [_timeArray removeAllObjects];
    [_LRCDictionary removeAllObjects];
    
    NSString* headerData = strGC;
    headerData = [headerData stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];  //去除掉首尾的空白字符和换行字符
    headerData = [headerData stringByReplacingOccurrencesOfString:@"\r" withString:@""];
    headerData = [headerData stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    NSString *contentStr2 = headerData;
    
    
    
    
    NSString * contentStr = [contentStr2 stringByReplacingOccurrencesOfString:@"<br/>" withString:@""];

    
    
    NSLog(@"%@", contentStr);
    
    //歌词为空时的处理
    if ([contentStr isEqualToString:@""]) {
        [_geciTableView addSubview:_zanwuLabel];
        [_geciTableView reloadData];
//        _geciTableView.hidden = YES;
        return;
    }
    //2.10 请求歌词为nil的修改
    if (contentStr == nil) {
        [_geciTableView addSubview:_zanwuLabel];
        [_geciTableView reloadData];
//        _geciTableView.hidden = YES;
        return;
    }
    
    [_zanwuLabel removeFromSuperview];
    _geciTableView.hidden = NO;
    
    
    NSArray * array = [contentStr componentsSeparatedByString:@"["];
    
//    for (NSString * str in array) {
//        NSLog(@"%@ ---%ld", str,str.length);
//    }
    
    //临时记录相同歌词的时间段
    NSMutableArray * tempTimeArr = [NSMutableArray arrayWithCapacity:1];
    for (int i = 0; i < [array count]; i++) {
        NSString *linStr = [array objectAtIndex:i];
        //        NSLog(@"%@", linStr);
        if (linStr.length<9 && linStr.length!=6) {
            continue;
        }
        if ([linStr rangeOfString:@"]"].length == 0) {
            continue;
        }
        
        NSArray *lineArray = [linStr componentsSeparatedByString:@"]"];
//        for (NSString * gecistr in lineArray) {
//            NSLog(@"%@ ====%ld", gecistr, gecistr.length);
//            if (gecistr.length==2 && [gecistr isEqualToString:@"  "]) {
//                NSLog(@"空行");
//            }
//        }
        

#pragma ---选择4的位置会有一些特殊的歌词有BUG---
        //            if (i >= 1) {
        NSString * lrcStr = [lineArray objectAtIndex:1];
        NSString * timeStr = [lineArray objectAtIndex:0];
        NSArray * intTime = [timeStr componentsSeparatedByString:@"."];
        [_timeArray addObject:[intTime objectAtIndex:0]];
        // ----(歌词重复问题)----
        if (lrcStr.length == 2 && [lrcStr isEqualToString:@"  "]) {
            [self.LRCDictionary setObject:@"  " forKey:[intTime objectAtIndex:0]];
        }else{
            if (lrcStr.length == 0) {
                [tempTimeArr addObject:[intTime objectAtIndex:0]];
            }else{
                [self.LRCDictionary setObject:lrcStr forKey:[intTime objectAtIndex:0]];
                for (NSString * tempTimeStr in tempTimeArr) {
                    [self.LRCDictionary setObject:lrcStr forKey:tempTimeStr];
                }
                [tempTimeArr removeAllObjects];
            }
        }
        //            }
        
    }
    
    NSLog(@"%ld", _timeArray.count);
    
    NSArray * tempTimeA = [NSArray arrayWithArray:_timeArray];
    tempTimeA = [tempTimeA sortedArrayUsingComparator:^NSComparisonResult(NSString* obj1, NSString* obj2) {
        NSArray * timeArr1 = [obj1 componentsSeparatedByString:@":"];
        NSInteger timeNumber1 = [[timeArr1 objectAtIndex:0] integerValue]*60 + [[timeArr1 objectAtIndex:1] integerValue];
        NSArray * timeArr2 = [obj2 componentsSeparatedByString:@":"];
        NSInteger timeNumber2 = [[timeArr2 objectAtIndex:0] integerValue]*60 + [[timeArr2 objectAtIndex:1] integerValue];
        if (timeNumber1 > timeNumber2) {
            return (NSComparisonResult)NSOrderedDescending;
        }
        if (timeNumber1 < timeNumber2) {
            return (NSComparisonResult)NSOrderedAscending;
        }
        return (NSComparisonResult)NSOrderedSame;

    }];
    [self.timeArray removeAllObjects];
    [self.timeArray addObjectsFromArray:tempTimeA];
    
    [self LRCandGCD];
}

- (void)LRCandGCD
{
    JKSongsMessStatus * status = [_songListArr objectAtIndex:_songIndex];
    NSMutableArray * geciArray = [NSMutableArray arrayWithCapacity:1];
    NSMutableDictionary * lrcDic = [NSMutableDictionary dictionaryWithCapacity:1];
    [lrcDic setValuesForKeysWithDictionary:self.LRCDictionary];
    NSMutableArray * timeArr = [NSMutableArray arrayWithCapacity:1];
    [timeArr addObjectsFromArray:_timeArray];
    [geciArray addObject:lrcDic];
    [geciArray addObject:timeArr];
    [[TheHomeManager shareTheHomeManager].playGeCiDic setObject:geciArray forKey:[NSString stringWithFormat:@"%@", status.songID]];
    [[TheHomeManager shareTheHomeManager] saveAllMusicAboutGeci];
    
    [self.geciTableView reloadData];

}




#pragma mark - 歌词与列表代理方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if ([tableView isEqual:_lieBiaoTableView]) {
        if ([TheHomeManager shareTheHomeManager].shengjPlayBool == 1) {
            if (self.localPlayBool) {
                return self.songListArr.count;
            }
            return [TheHomeManager shareTheHomeManager].dataShengJingSongsArr.count;
        }
        return _songListArr.count;
    }
//    NSLog(@"%ld", self.timeArray.count);
    
    return self.timeArray.count;
}







@end
